package com.example.pachong.service.impl;

import com.example.pachong.mapper.IpMapper;
import com.example.pachong.pojo.Ip;
import com.example.pachong.service.IpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class IpServiceImpl implements IpService {

    @Autowired
    private IpMapper ipmapper;

    @Override
    public void tianjia(Ip ip) {
        Ip ips = ipmapper.selectByUid(ip.getIdip());
        if(ips != null){
            if(!ips.getIpcol().contains(ip.getIpcol())) {
                ip.setIpfreq(ips.getIpfreq() + 1);
                ip.setIpcol(ip.getIpcol()+"/"+ips.getIpcol());
                ipmapper.updateUser(ip);
            }
        }else{
            ip.setIpfreq(0);
            ipmapper.insertUser(ip);
        }
    }
}
